using System;
using System.Timers;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Campus
{
    class Physicist : Unit
    {
        #region Fields and Properties

        static public List<Texture2D> idleAnim = new List<Texture2D>();
        static public List<Texture2D> walkRightAnim = new List<Texture2D>();
        static public List<Texture2D> walkLeftAnim = new List<Texture2D>();
        static public List<Texture2D> walkUpAnim = new List<Texture2D>();
        static public List<Texture2D> walkDownAnim = new List<Texture2D>();
        static public List<Texture2D> attackRightAnim = new List<Texture2D>();
        static public List<Texture2D> attackLeftAnim = new List<Texture2D>();
        static public List<Texture2D> dieAnim = new List<Texture2D>();

        #endregion

        #region Constructors

        public Physicist(Vector2 position, Player player, Level level)
            : base(CreateDictionary(), position, 50, player, level,
            new Dictionary<String, Ability>(), new Dictionary<String, AbilitySubMenu>())
        {
            m_name = "Physicist";
            m_entitySelectedImage = idleAnim[0];
            Size = new Vector2(60, 60);
            CreateAbilites();
        }

        #endregion

        #region Methods

        private void CreateAbilites() 
        {
            Abilities.Add("Move", new MoveAbility(this, Vector2.Zero));
            Abilities.Add("Attack", new MeleeAttack(this, null, Ability.TargetTypes.BaseEntityTarget, 10, 15, 1000));
            Abilities.Add("Build Clean Room", new BuildStructureAbility(MenuIcons.BuildCleanRoomIcon, this, BuildRequirements.Buildings.CleanRoom));
            Abilities.Add("Build Scholarip", new BuildStructureAbility(MenuIcons.BuildScholarshipIcon, this, BuildRequirements.Buildings.Scholarship));
            Abilities.Add("Build Gateway To Hell", new BuildStructureAbility(MenuIcons.BuildGatewayToHellIcon, this, BuildRequirements.Buildings.GatewayToHell));
            Abilities.Add("Build Down By The River", new BuildStructureAbility(MenuIcons.BuildDownByTheRiverIcon, this, BuildRequirements.Buildings.DownByTheRiver));
            this.CanAttack = true;
        }

        public override void Update(GameTime gameTime, bool checkInput, bool updateBoundingBox)
        {            
            base.Update(gameTime, checkInput, updateBoundingBox);
        }
        
        //QUESTION: why is this here, never used
        private double FindDistance(BaseEntity target)
        {
            double x = (Position.X + Size.X / 2) - (target.Position.X + target.Size.X / 2);
            double y = (Position.Y + Size.Y / 2) - (target.Position.Y + target.Size.Y / 2);

            return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
        }

        static private Dictionary<Unit.UnitState, Animation> CreateDictionary()
        {
            Dictionary<Unit.UnitState, Animation> dict = new Dictionary<UnitState, Animation>();

            // Creates an animation based on the certain static list, then adds it to the
            // Dictionary under the appropriate state.
            dict.Add(UnitState.Idle, new Animation(idleAnim, 1000, true));
            
            dict.Add(UnitState.WalkRight, new Animation(walkRightAnim, 75, true));
            dict.Add(UnitState.WalkLeft, new Animation(walkLeftAnim, 75, true));
            dict.Add(UnitState.WalkDown, new Animation(walkDownAnim, 75, true));
            dict.Add(UnitState.WalkUp, new Animation(walkUpAnim, 75, true));
            dict.Add(UnitState.AttackRight, new Animation(attackRightAnim, 100, false));
            dict.Add(UnitState.AttackLeft, new Animation(attackLeftAnim, 100, false));
            dict.Add(UnitState.Die, new Animation(dieAnim, 100, false));

            return dict;
        }


        static public void InitializeAnimations(ContentManager Content)
        {
            // Loads all the idle animation frames
            idleAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistIDLE_1"));
            idleAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistIDLE_0"));
            idleAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistIDLE_2"));

            walkRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKRIGHT_0"));
            walkRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKRIGHT_1"));
            walkRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKRIGHT_2"));
            walkRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKRIGHT_3"));

            walkLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKLEFT_0"));
            walkLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKLEFT_1"));
            walkLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKLEFT_2"));
            walkLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKLEFT_3"));

            walkDownAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKDOWN_0"));
            walkDownAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKDOWN_1"));
            walkDownAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKDOWN_2"));
            walkDownAnim.Add(walkDownAnim[2]);
            walkDownAnim.Add(walkDownAnim[1]);
            walkDownAnim.Add(walkDownAnim[0]);
            walkDownAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKDOWN_3"));
            walkDownAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKDOWN_4"));
            walkDownAnim.Add(walkDownAnim[6]);
            walkDownAnim.Add(walkDownAnim[5]);

            walkUpAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKUP_0"));
            walkUpAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKUP_1"));
            walkUpAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKUP_2"));
            walkUpAnim.Add(walkUpAnim[2]);
            walkUpAnim.Add(walkUpAnim[1]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKUP_3"));
            walkUpAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistWALKUP_4"));
            walkUpAnim.Add(walkUpAnim[6]);
            walkUpAnim.Add(walkUpAnim[5]);

            attackRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKRIGHT_0"));
            attackRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKRIGHT_1"));
            attackRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKRIGHT_2"));
            attackRightAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKRIGHT_3"));

            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKLEFT_0"));
            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKLEFT_1"));
            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKLEFT_2"));
            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistATTACKLEFT_3"));

            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_0"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_1"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_2"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_3"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_4"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_5"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_6"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_7"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_8"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_9"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_10"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_11"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_12"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_13"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_14"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_15"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_16"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_17"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_18"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_19"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Physicist/physicistDEATH_20"));
        }

        #endregion
    }
}